﻿using System.Configuration;
using System.Web;
using System.Web.Mvc;
using Business;
using Dto;
using System;

namespace YaoYunDong.Controllers
{
    public class AlbumController : BaseController
    {
        private readonly UserPhotoBusiness _userPhotoBusiness = new UserPhotoBusiness();
        private readonly string ImageLoadUrl = ConfigurationManager.AppSettings["ImageLoadUrl"];
        private readonly string PhotoNarrowPath = ConfigurationManager.AppSettings["PhotoNarrowPath"];
        private readonly string PhotoOriginalPath = ConfigurationManager.AppSettings["PhotoOriginalPath"];

        public ActionResult FckImg()
        {
            var json = _userPhotoBusiness.GetPhotoJSON(UserDto.UserId);
            ViewData["ImageBasePath"] = ImageLoadUrl;
            ViewData["JSON"] = json;
            return View();
        }

        public string SavePhotoSimple(HttpPostedFileBase FilePhoto, int albumId)
        {
            var annexDto = Iuu.ImageUpload(PhotoNarrowPath, PhotoOriginalPath, 170, 170, FilePhoto, null, null, true);
            var dto = new UserPhotoDto
            {
                PhotoAnnexId = annexDto.AnnexID,
                PhotoAlbumId = albumId,
                PhotoName = annexDto.AnnexName,
                PhotoDesc = "",
                PhotoTime = DateTime.Now,
                PhotoUserId = UserDto.UserId
            };
            int annexID;
            _userPhotoBusiness.SaveUserAlbum(dto, annexDto, null, false, out annexID);

            return annexDto.AnnexName + "," + annexID;
        }
    }
}
